# +--------------------------
# | User: zq                -
# | Version: python3.7      -
# | Time: 2020-03-13 15:51                
# +--------------------------
from peewee import *

db = MySQLDatabase("spider_csdn", host="47.111.17.68", port=3306, user="spider_csdn", password="wuhu@888")


# db = MySQLDatabase("spider_jd", host="localhost", port=3306, user="root", password="root")


class BaseModel(Model):
    class Meta:
        database = db


# 设计数据表的时候有几个重要点
# 1. char类型要设置最大长度,默认255
# 2. 对于无法确定最大长度的字段,可以设置为 Text
# 3. 设计表的时候,采集到的数据要尽量先做格式化处理
# 4. default 和 null=True的情况

# 商品表
class Good(BaseModel):
    id = IntegerField(primary_key=True, verbose_name="商品id")
    name = CharField(max_length=500, verbose_name="商品名称")
    content = TextField(default="", verbose_name="商品描述")
    supplier = CharField(default="", max_length=500)  # 自营还是第三方商家
    ggbz = TextField(default="", verbose_name="规格和包装")  # verbose_name注释
    image_list = TextField(default="", verbose_name="商品图片列表")  # 图片list
    price = FloatField(default=0.0, verbose_name="商品价格")

    good_rage = IntegerField(default=0, verbose_name="好评率")
    comments_nums = IntegerField(default=0, verbose_name="评论数")
    has_image_comment_nums = IntegerField(default=0, verbose_name="晒图数")
    has_video_comment_nums = IntegerField(default=0, verbose_name="视频晒单数")
    has_add_comment_nums = IntegerField(default=0, verbose_name="追评数")
    good_comment_nums = IntegerField(default=0, verbose_name="好评数")
    middle_comment_nums = IntegerField(default=0, verbose_name="中评数")
    bad_comment_nums = IntegerField(default=0, verbose_name="差评数")


# 评价表
class GoodEvaluate(BaseModel):
    id = CharField(primary_key=True)
    good = ForeignKeyField(Good, verbose_name="商品")
    user_head_url = CharField(verbose_name="用户头像")
    user_name = CharField(verbose_name="用户名")
    good_info = CharField(max_length=500, verbose_name="购买商品的信息")
    evaluate_time = DateTimeField(verbose_name="评价时间")
    content = TextField(default="", verbose_name="评价内容")
    star = IntegerField(default=0, verbose_name="评分")
    comment_nums = IntegerField(default=0, verbose_name="该条评论中的评论数")
    praised_nums = IntegerField(default=0, verbose_name="该条评论中的点赞数")
    image_list = TextField(default="", verbose_name="图片")
    video_list = TextField(default="", verbose_name="视频")


# 商品总结信息评论表
class GoodEvaluateSummary(BaseModel):
    good = ForeignKeyField(Good, verbose_name="商品")
    tag = CharField(max_length=20, verbose_name="标签")
    num = IntegerField(default=0, verbose_name="数量")


if __name__ == "__main__":
    db.create_tables([Good, GoodEvaluate, GoodEvaluateSummary])
